# Check ArkUI project syntax errors

Write-Host "=== Checking ArkUI Project Syntax Errors ===" -ForegroundColor Green

$etsFiles = Get-ChildItem -Path "d:\zuizhongban\entry\src\main\ets\pages" -Filter "*.ets" -Recurse

Write-Host "`nFound .ets files:" -ForegroundColor Yellow
foreach ($file in $etsFiles) {
    Write-Host "  - $($file.Name)" -ForegroundColor Cyan
}

Write-Host "`n=== Checking Common Syntax Errors ===" -ForegroundColor Green

$errorCount = 0

foreach ($file in $etsFiles) {
    Write-Host "`nChecking file: $($file.Name)" -ForegroundColor Yellow
    $content = Get-Content $file.FullName -Raw
    
    # Check @kit.ArkUI import errors
    if ($content -match "from\s+['\`"]@kit\.ArkUI['\`"]") {
        Write-Host "  ERROR: Found @kit.ArkUI import error" -ForegroundColor Red
        $errorCount++
    } else {
        Write-Host "  OK: No @kit.ArkUI import errors" -ForegroundColor Green
    }
    
    # Check private property errors
    if ($content -match "private\s+\w+:\s*\w+.*=") {
        Write-Host "  ERROR: Found private property issues" -ForegroundColor Red
        $errorCount++
    } else {
        Write-Host "  OK: No private property errors" -ForegroundColor Green
    }
    
    # Check Flex component usage
    if ($content -match "Flex\s*\(") {
        Write-Host "  WARNING: Found Flex component usage" -ForegroundColor Yellow
    } else {
        Write-Host "  OK: No Flex component usage" -ForegroundColor Green
    }
    
    # Check undefined components
    $undefinedComponents = @()
    if ($content -match "\bTag\b" -and $content -notmatch "struct Tag") {
        $undefinedComponents += "Tag"
    }
    
    if ($undefinedComponents.Count -gt 0) {
        Write-Host "  ERROR: Found undefined components: $($undefinedComponents -join ', ')" -ForegroundColor Red
        $errorCount++
    } else {
        Write-Host "  OK: No undefined components" -ForegroundColor Green
    }
    
    # Check basic syntax structure
    if ($content -match "@Entry" -and $content -match "@Component" -and $content -match "struct \w+") {
        Write-Host "  OK: Basic structure correct" -ForegroundColor Green
    } else {
        Write-Host "  ERROR: Basic structure issues" -ForegroundColor Red
        $errorCount++
    }
}

Write-Host "`n=== Check Results Summary ===" -ForegroundColor Green
if ($errorCount -eq 0) {
    Write-Host "SUCCESS: All files passed, no syntax errors found!" -ForegroundColor Green
} else {
    Write-Host "WARNING: Found $errorCount potential issues" -ForegroundColor Red
}

Write-Host "`n=== Project File Structure Check ===" -ForegroundColor Green
$requiredFiles = @(
    "d:\zuizhongban\entry\src\main\ets\pages\Index.ets",
    "d:\zuizhongban\entry\src\main\ets\pages\injuryAssessment.ets",
    "d:\zuizhongban\entry\src\main\ets\pages\rehabilitationLibrary.ets",
    "d:\zuizhongban\entry\src\main\ets\pages\myRehabilitationPlans.ets",
    "d:\zuizhongban\entry\src\main\ets\pages\rehabilitationPlan.ets"
)

foreach ($file in $requiredFiles) {
    if (Test-Path $file) {
        Write-Host "  OK: $([System.IO.Path]::GetFileName($file))" -ForegroundColor Green
    } else {
        Write-Host "  ERROR: $([System.IO.Path]::GetFileName($file)) missing" -ForegroundColor Red
    }
}

Write-Host "`nCheck completed!" -ForegroundColor Green